const state = {
    addressList: JSON.parse(uni.getStorageSync('addressList') || '{}'),
    token: uni.getStorageSync('token') || '',
    userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
    redirectInfo: null
}
const mutations = {
    // 更新地址信息
    updateAddress(state, address) {
        state.addressList = address
        this.commit('user/saveSetAddressStorage')
    },
    saveSetAddressStorage(state) {
        uni.setStorageSync('addressList', JSON.stringify(state.addressList))
    },
    // 更新用户信息
    updateUserInfoObj(state, userInfo) {
        state.userInfo = userInfo
        this.commit('user/saveSetUserInfoStorage')
    },
    saveSetUserInfoStorage(state) {
        uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
    },
    // 更新token信息
    updateToken(state, token) {
        state.token = token
        this.commit('user/saveTokenStorage')
    },
    saveTokenStorage(state) {
        uni.setStorageSync('token', JSON.stringify(state.token))
    },
    removeToken() {
        uni.removeStorageSync('token')
    },
    // 更新redirect信息
    updateRedirectInfo(state, info) {
        state.redirectInfo = info
    },

}
const actions = {}
const getters = {
    // 收货地址
    deliveryAddress(state){
        if (!state.addressList.provinceName) return ''
        return state.addressList.provinceName + state.addressList.cityName + state.addressList.countyName + state.addressList.detailInfo
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}